package com.actionsky.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.actionsky.dao.NewsActiveDAO;
import com.actionsky.entity.NewsActive;
import com.actionsky.entity.PageSet;

public class NewsMore extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	List<NewsActive> newsList = null;
	List<NewsActive> activeList = null;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		//查询更多新闻或行业动态，按类型1，新闻 2，行业
		int type = Integer.parseInt(request.getParameter("type"));
		//页数
		int page_number = Integer.parseInt(request.getParameter("page"));
		int int_page_number=(page_number-1)*10;		//int_page_number 从第几条记录开始
		int rowcount=0;
		//新闻查询
		if(type==1){
			newsList = NewsActiveDAO.findNewsActiveByType(1, int_page_number, 10);
			rowcount = NewsActiveDAO.countByType(1);
			if(rowcount==0) rowcount=1;
			request.getSession().setAttribute("newsList",newsList);
			PageSet pageset=new PageSet();
			pageset.setRowcount(rowcount);
			pageset.setCurrentpage(page_number);
			pageset.setPagecount((rowcount+10-1)/10);
			pageset.setPagesize(10);
			request.getSession().setAttribute("pageset_news", pageset);
			response.sendRedirect("corporate-news/index.jsp");
		}else{
			activeList = NewsActiveDAO.findNewsActiveByType(2, int_page_number, 10);
			rowcount = NewsActiveDAO.countByType(2);
			if(rowcount==0) rowcount=1;
			request.getSession().setAttribute("activeList",activeList);
			PageSet pageset=new PageSet();
			pageset.setRowcount(rowcount);
			pageset.setCurrentpage(page_number);
			pageset.setPagecount((rowcount+10-1)/10);
			pageset.setPagesize(10);
			request.getSession().setAttribute("pageset_news", pageset);
			response.sendRedirect("industries-news/index.jsp");
		}
	}

	public void init() throws ServletException {
	}
	public void destroy() {
		super.destroy(); 
	}
}
